package core.tests;
import core.models.*;
import core.models.items.*;
import java.util.List;
import java.util.ArrayList;

import junit.framework.TestCase;

import org.junit.Test;

public class InventoryTest extends TestCase{

	Inventory temp = new Inventory();
	List<Item> list = new ArrayList<Item>();
	Bullet bill = new Bullet(15);	
	Bullet bob = new Bullet(14);
	Clothing c1 = new Clothing(25);
	Clothing c2 = new Clothing(10);
	Food f1 = new Food(20);
	Food f2 = new Food(25);
	Medicine m1 = new Medicine(10);
	Medicine m2 = new Medicine(99);
	
	
	@Test
	public void testAdd() 
	{
		temp.add(bill);
		assertEquals(bill,temp.getItems().get(0));
		temp.add(bob);
		assert(temp.getItems().size()==1);
		assertEquals(temp.getItems().get(0).getQuantity(),29);
		assertFalse(temp.getItems().size()==2);
		
		temp.add(m1);
		temp.add(m2);
		assertEquals(temp.getItems().size(),2);
		assertEquals(temp.getItems().get(1).getQuantity(),(m1.getQuantity()));
		assertEquals(temp.getItems().get(1).getQuantity(),109);
	}
	
	@Test
	public void testAddList()
	{
		temp.clean();
		ArrayList<Item> tempList = new ArrayList<Item>();
		tempList.add(bill);
		tempList.add(c1);
		temp.add(tempList);
		assert(temp.getItems().size()==2);		
		tempList.clear();
		tempList.add(c2);
		tempList.add(m1);
		temp.add(tempList);
		assert(temp.getItems().size()==3);
		assert(temp.getItems().get(0).getQuantity()==15);
		assert(temp.getItems().get(1).getQuantity()==39);
		assertEquals(temp.getItems().get(2).getQuantity(),10);
	}
	@Test
	public void testRemove()
	{
//		List of items to remove from inventory
		list.clear();
		list.add(m1);
		
//		Items in inventory
		temp.add(bill);
		temp.add(m1);
		temp.add(f2);
		assert(temp.getItems().size()==3);
		temp.remove(list);
		assert(temp.getItems().size()==2);
//		Making sure you cant remove the same item twice
		temp.remove(list);
		assert(temp.getItems().size()==2);
//		Remove all items in the list
		list.clear();
		list.add(bill);
		list.add(m1);
		list.add(f2);
		temp.getItems().clear();
		
		temp.add(list);
		assert(temp.getItems().size()==3);
		temp.remove(list);
		assert(temp.getItems().size()==0);
	}
	
	@Test
	public void testClean()
	{
		temp = new Inventory();
		temp.clean();
		// Checks that clean on an empty list doesn't muck anything up.
		assertEquals(0, temp.getTotalWeight()); 
		
		ArrayList<Item> tempList = new ArrayList<Item>();
		tempList.add(bill);
		temp.add(tempList);
		temp.clean();
		// Checks to make sure one item with quantity > 0 don't get removed.
		assertEquals(45, temp.getTotalWeight());
		
		temp = new Inventory();
		tempList.add(bill);
		tempList.add(c1);
		tempList.add(f1);
		temp.add(tempList);
		temp.clean();
		// Checks to make sure multiple items aren't affected.
		assertEquals(115, temp.getTotalWeight());
		
		bill.setQuantity(0);
		temp.clean();
		// Checks to see if clean will remove one item.
		assertEquals(70, temp.getTotalWeight());
		
		c1.setQuantity(0);
		f1.setQuantity(0);
		temp.clean();
		// Checks to see if all items will be removed.
		assertEquals(0, temp.getTotalWeight());
		
	}
	
	public void testGetTotalWeight()
	{
		temp = new Inventory();
		temp.getTotalWeight();
		//check weight of empty inventory is zero
		assertEquals(0, temp.getTotalWeight());
		
		ArrayList<Item> tempList = new ArrayList<Item>();
		tempList.add(bill);
		tempList.add(bob);
		temp.clean();
		temp.add(tempList);
		temp.getTotalWeight();
		//check weight of inventory with items in it
		assertEquals(87, temp.getTotalWeight());
		
		bill.setQuantity(-5);
		bob.setQuantity(-2);
		//check that negative quantities are not allowed and weight will not be negative
		assertEquals(87, temp.getTotalWeight());
		
		bill.setQuantity(0);
		bob.setQuantity(0);
		temp.clean();
		//check if weight is reset to zero
		assertEquals(0, temp.getTotalWeight());
	}
}
